package com.suning.sawp.web.controller;

import java.security.Principal;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.suning.sawp.constants.RegAndBindErrCodeConstants;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.intf.taskCard.IndexTaskCardService;
import com.suning.sawp.intf.taskCard.vo.TaskCardResponse;
import com.suning.sawp.web.exception.MyGsonView;

/**
 * 首页任务卡接口 〈一句话功能简述〉<br>
 * 〈功能详细描述〉
 *
 * @author 15050519
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@RequestMapping("/index")
public class IndexTaskCardController extends DjBaseController {

    /**
     * 日志
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(IndexTaskCardController.class);

    /**
     * 任务卡服务
     */
    @Autowired
    IndexTaskCardService indexTaskCardService;

    /**
     * 查询任务卡列表 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryTaskCards.do")
    public MyGsonView queryTaskCards(Principal principal) {
        LOGGER.debug("queryTaskCards enter,staffId:{}", principal.getName());
        ReturnMsg<TaskCardResponse> ret = new ReturnMsg<TaskCardResponse>();
        String staffId = principal.getName();
        try {
            TaskCardResponse resp = indexTaskCardService.queryTaskCard(staffId);
            LOGGER.debug("queryTaskCards, response:{}", resp);
            ret.setData(resp);
        } catch (Exception e) {
            ret.setRetFlag(ReturnMsg.FAIL);
            ret.setErrorCode(RegAndBindErrCodeConstants.COMMON_ERR_E999);
            ret.setErrorMessage(
                    RegAndBindErrCodeConstants.COMMON_ERR_MAP.get(RegAndBindErrCodeConstants.COMMON_ERR_E999));
            LOGGER.error("queryTaskCards,staffId:" + principal.getName(), e);
        }
        LOGGER.debug("queryTaskCards exit,staffId:{},ret:{}", principal.getName(), ret);
        return setGsonView(ret);
    }
}
